package models

import (
	"gorm.io/gorm"
	"srv/basic/config"
)

type Car struct {
	gorm.Model
	UserId  int    `json:"user_id" gorm:"int;unique"`
	License string `json:"plate" gorm:"type:varchar(10);index;unique"` //车牌号
	Brand   string `json:"brand" gorm:"varchar(20)" `                  //品牌
	Color   string `json:"color" gorm:"varchar(10)"`                   //颜色
	Seats   int64  `json:"seats" gorm:"int;comment:座位数"`
	CarUrl  string `json:"car_url" gorm:"type:varchar(300);comment:'车辆图片'"`
	CType   string `json:"c_type" gorm:"type:varchar(20);index;comment:车辆类型"`
}

func (c *Car) TableName() string {
	return "car"
}

func (c *Car) Create() error {
	return config.DB.Create(&c).Error
}

func (c *Car) GetCarInfoByLicense() error {
	return config.DB.Where("license = ?", c.License).Find(&c).Error
}

func (c *Car) GetCarTypeList() (carList []string, err error) {
	err = config.DB.Model(&c).Select("c_type").Find(&carList).Error
	return
}
